
using UnityEngine;
using WooEngine.Utility.Math;

namespace WooEngine.UI.Base
{
    [AddComponentMenu("Layout/Radian Layout Group", 153)]
    public class UIRadianGroup : MonoBehaviour
    {

        [SerializeField] protected float m_Top = 0;
        [SerializeField] protected float m_Radian = 0;
        [SerializeField] protected float m_WeightHalf = 0;

        public void Refresh()
        {
            float count = this.transform.childCount;
            if (count <= 0)
                return;
            Vector3 p0 = new Vector3(-m_WeightHalf, m_Top, 0);
            Vector3 p2 = new Vector3(m_WeightHalf, m_Top, 0);
            Vector3 p1 = new Vector3(0, m_Radian + m_Top, 0);
            if (count == 1)
            {
                this.transform.GetChild(0).transform.localPosition = BezierCurveUtils.Bezier2(p0, p1, p2, 0.5f);
            }
            else
            {
                for (int i = 0; i < count; i++)
                {
                    float t = (1 / count) / 2 + (i / count);
                    this.transform.GetChild(i).transform.localPosition = BezierCurveUtils.Bezier2(p0, p1, p2, t);
                }
            }
        }

        private void Update()
        {
            Refresh();
        }
    }
}